package cn.kgc.service.impl;

import cn.kgc.client.ClazzClient;
import cn.kgc.dao.GroupDao;
import cn.kgc.entity.Clazz;
import cn.kgc.entity.Group;
import cn.kgc.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author mosin
 * date 2022/1/17
 * @version 1.0
 */
@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupDao groupDao;

    @Autowired
    private ClazzClient clazzClient;

    @Override
    public List<Group> queryAll() {
        List<Group> groups = groupDao.queryAll();
        groups.forEach(group -> {
            String clazzId = group.getClazzId();
            //调用班级微服务 利用id 查询班级信息
            Clazz clazz = clazzClient.getClazz(Integer.parseInt(clazzId));
            group.setClazz(clazz);

        }) ;
        return groups;
    }

    @Override
    public Group addGroup(Group group) {
        group.setCreateDate(new Date());
        groupDao.add(group);
        return group;
    }

    @Override
    public Group getOne(Integer id) {

        Group group =  groupDao.getOne(id);
        return group;
    }
}
